package cn.com.dycc.task_manage.ordermain.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dycc.common.controller.BaseController;
import cn.com.dycc.task_manage.ordermain.entity.ResultOrderMain;
import cn.com.dycc.task_manage.ordermain.entity.UserOrderEntity;
import cn.com.dycc.task_manage.ordermain.param.FindAllParam;
import cn.com.dycc.task_manage.ordermain.param.SendingListsParam;
import cn.com.dycc.task_manage.ordermain.service.OrderMainService;
import cn.com.dycc.util.JsonObjectResult;
/**
 * 工单控制层
 * @author linfa
 *
 */
@Controller
@RequestMapping("main")
public class OrderMainController extends BaseController{
	
	@Resource(name="orderMainService")
	private OrderMainService orderMainService;
	
	//发送工单
	@ResponseBody
	@RequestMapping(value="/add.do",method ={RequestMethod.POST})
	public JsonObjectResult sendOrderMain(HttpServletRequest request,@RequestBody SendingListsParam sendingListsParam){
//		System.out.println("sendingListsParam="+sendingListsParam);
		String mes = orderMainService.sendOrderMain(request, sendingListsParam);
		return new JsonObjectResult(mes);
	}
	
	//根据order_id查询工单主表信息
	@ResponseBody
	@RequestMapping("/find.do")
	public JsonObjectResult findUserOrderByOrderId(HttpServletRequest request,String order_id){
		UserOrderEntity userOrderEntity = orderMainService.findUserOrderByOrderId(request,order_id);
		return new JsonObjectResult(userOrderEntity);
	}
	
	//根据登录用户查询所有自己发送的工单
	@ResponseBody
	@RequestMapping("/all.do")
	public JsonObjectResult findAll(HttpServletRequest request,FindAllParam findAllParam,String status){
		List<ResultOrderMain> list = orderMainService.findAll(request, findAllParam,status);
		String count = orderMainService.findAllCount(request,status,findAllParam.getOrder_title());
		return new JsonObjectResult(count,list);
	}

}
